cmake_minimum_required(VERSION 3.10)

# ----------------------
# 基础配置
# ----------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 定义路径变量（明确项目结构）
set(PROJECT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(PROJECT_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")

# ----------------------
# 依赖查找
# ----------------------
find_package(nlohmann_json REQUIRED)

# ----------------------
# 静态库定义
# ----------------------
set(MODEL_SDK_LIBRARY ${PROJECT_NAME}_model_static)
set(AI_COMMON_LIBRARY ${PROJECT_NAME}_common_static)
set(PT_SDK_LIBRARY ${PROJECT_NAME}_pt_static)

add_library(${MODEL_SDK_LIBRARY} STATIC
    ${PROJECT_SRC_DIR}/model_builder.cpp
)

# ----------------------
# 头文件管理
# ----------------------
target_include_directories(${MODEL_SDK_LIBRARY}
    PUBLIC  # 外部项目包含此路径即可使用库接口
        ${PROJECT_INCLUDE_DIR}
    PRIVATE # 内部编译时需要的头文件路径
        ${CMAKE_SOURCE_DIR}/pt_sdk/include     # 添加 pt_sdk 头文件路径
        ${CMAKE_SOURCE_DIR}/common/include     # 添加 common 头文件路径
)

# 指定公共头文件（用于安装和IDE索引）
set_target_properties(${MODEL_SDK_LIBRARY} 
    PROPERTIES
    PUBLIC_HEADER "include/model_builder.h"
)

# ----------------------
# 编译选项
# ----------------------
target_compile_options(${MODEL_SDK_LIBRARY} PRIVATE
    $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -pedantic> #  -Wno-c++11-long-long
    $<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -pedantic -Wno-unknown-pragmas>
    $<$<CXX_COMPILER_ID:AppleClang>:-Wall -Wextra -pedantic -Wno-unknown-pragmas>
)

# ----------------------
# 依赖链接（静态库内部依赖）
# ----------------------
target_link_libraries(${MODEL_SDK_LIBRARY} 
    PUBLIC
        ${AI_COMMON_LIBRARY} 
        ${PT_SDK_LIBRARY}           # 添加对 pt_sdk 库的依赖
        nlohmann_json::nlohmann_json
)

# ----------------------
# 安装配置（可选，用于打包）
# ----------------------
install(TARGETS ${MODEL_SDK_LIBRARY}
    ARCHIVE DESTINATION lib
    PUBLIC_HEADER DESTINATION include
)